<%--
  Created by IntelliJ IDEA.
  User: jt
  Date: 2021/6/29
  Time: 15:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/css/bootstrap.css">
<link href="${ctx }/js/plugs/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/js/plugs/jquery-ui-1.10.3.custom/js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="${ctx }/js/plugs/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />
<!-- 新 Bootstrap 核心 CSS 文件 -->
<!-- <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"> -->
<link rel="stylesheet" href="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/css/bootstrap.css">
<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<!-- <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap-theme.min.css"> -->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<!-- <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> -->
<script src="${ctx }/js/plugs/bootstrap-3.3.0-dist/dist/js/bootstrap.js"></script>
<!-- <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> -->

<head>
    <title>机构管理</title>
</head>

<body>
<style>
    table,table tr th, table tr td { border:1px solid black; }
</style>
<script>

    $.ajax({
        type:"get",
        url:"/Insrole/selectall.do",
        dataType:"json",
        success:function (data) {

            var html="";
            var neirong="";

            for (let i = 0; i <data.length ; i++) {

                var id=data[i]["org_id"];

                var orgname=data[i]["org_name"];
                neirong="<tr>\n" +
                    "            <td>"+id+"</td>\n" +
                    "            <td>"+orgname+"</td>\n" +
                    "            <td><a href='/Insrole/selectuser.do?id="+id+"'>编辑</a></td>\n" +
                    "        </tr>"
                console.log(neirong)
                html=html+neirong;

            }
            console.log(html);
            document.getElementById("table").innerHTML=document.getElementById("table").innerHTML+html;
        }
    })

    function create(){
        var surveyId=$(this).parents("tr").find("input[name='surveyId']").val();
        var titleValue=$(this).parents("tr").find(".titleTag").text();

        $("body").append("<div id=\"myDialogRoot\"><div class='dialogMessage' style='padding-top:40px;margin-left:20px;padding-bottom:0px;'>"+
            "<div>请输入机构id：<input id='surTitleid' type='text' style='padding:5px;width:320px;color:rgb(14, 136, 158);' value=''></div><div>请输入机构名称：<input id='surTitleTemp' type='text' style='padding:5px;width:320px;color:rgb(14, 136, 158);' value=''></div></div></div>");

        var myDialog=$( "#myDialogRoot" ).dialog({
            width:500,
//		height:220,
            autoOpen: true,
            modal:true,
            position:["center","center"],
            title:"创建",
            resizable:false,
            draggable:false,
            closeOnEscape:false,
            show: {effect:"blind",direction:"up",duration: 500},
            hide: {effect:"blind",direction:"left",duration: 200},
            buttons: {
                "OK":{
                    text: "确认新建",
                    addClass:'dialogMessageButton dialogBtn1',
                    click: function() {
                        //执行发布
                        var surveyName=$("#surTitleTemp").val();
                        var surveyid=$("#surTitleid").val();
                        surveyName=optionValue=escape(encodeURIComponent(surveyName));
                        surveyid=optionValue=escape(encodeURIComponent(surveyid));
                        <%--var params="id="+surveyid+"&orgname="+surveyName;--%>
                        <%--window.location.href="${ctx}/Insrole/createorganization.do?"+params;--%>

                    //
                        $.ajax({
                            type:"get",
                            url:"${ctx}/Insrole/createorganization.do",
                            data:{
                                id:surveyid,
                                orgname:surveyName
                            },
                            dataType:"json",
                            success:function (data) {
                                if(data[0]==1){
                                    window.location.href="${ctx}/Insrole/edit.do";
                                }else {
                                    alert("请勿重复创建");
                                    window.location.href="${ctx}/Insrole/edit.do";
                                }
                            },
                            catch:function (error) {
                                alert("请勿重复创建");
                                window.location.href="${ctx}/Insrole/edit.do";
                            }
                        })
                    }
                },
                "CENCEL":{
                    text: "取消",
                    addClass:"dialogBtn1 dialogBtn1Cencel",
                    click: function() {
                        $( this ).dialog( "close" );
                    }
                }
            },
            open:function(event,ui){
                $(".ui-dialog-titlebar-close").hide();
                $("#surTitleTemp").val(titleValue+"");
            },
            close:function(event,ui){
                $("#myDialogRoot").remove();
            }
        });
        return false;
    }
</script>
<input onclick="create()" type="button" class="sbtn25 sbtn25_1" value="创建" style="margin-left:20%;margin-top: 50px">
<table id="table" style="width:60%;margin-left:20%;margin-top: 30px;text-align: center" border="0" cellspacing="0">
    <tr>
        <td>机构ID</td>
        <td>机构名称</td>
        <td>操作</td>
    </tr>
</table>
</body>
</html>
